<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "{{%region}}".
 *
 * @property int $id ID
 * @property string $name 名称
 * @property int $pid 父ID
 * @property int $level 级联
 * @property string $letter 首字母
 * @property int $sort 排序
 * @property int $status 状态,0:禁用 1:正常
 */
class Region extends \builder\base\BaseActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return '{{%region}}';
    }

    /**
     * {@inheritdoc}
     */
    public function behaviors()
    {
        return [];
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['id', 'name', 'pid', 'level', 'letter', 'sort', 'status'], 'required'],
            [['id', 'pid', 'level', 'sort', 'status'], 'integer'],
            [['status'], 'in', 'range' => [0, 1]],
            [['name'], 'string', 'max' => 50],
            [['letter'], 'string', 'max' => 1],
            [['id'], 'unique'],
        ];
    }

    public function scenarios()
    {
        $scenarios = parent::scenarios();
        //编辑
        $scenarios['SCE_Region_Edit'] = ['name', 'sort', 'status'];
        //排序
        $scenarios['SCE_Region_Sort'] = ['sort'];

        return $scenarios;
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'name' => '名称',
            'pid' => '父ID',
            'level' => '级联',
            'letter' => '首字母',
            'sort' => '排序',
            'status' => '状态',
        ];
    }
}
